package com.corejsf;
import java.io.Serializable;

/**
 * This class stores data on a registered user.
 *
 * @author Victor Lu
 * @author Vukasin Simic
 * @version 1.0
 */
public class User implements Serializable{
    /**
     * serial Version UID.
     */
    private static final long serialVersionUID = -3346017799022042616L;
    /**
     * Max number of digits to pad employee number to with zeroes.
     */
    private static final int EMPNUMDIGITS = 5;
    /**
     * Uniquely identifying username.
     */
    private String userName;
    /**
     * User last name.
     */
    private String lastName;
    /**
     * User first name.
     */
    private String firstName;
    /**
     * User password, checked against for authentication.
     */
    private String password;
    /**
     * User Admin authorization.
     */
    private boolean admin;
    /**
     * Uniquely identifying number assigned by UserManger.
     */
    private int employeeNumber;
    /**
     * Indicator of whether User is being edited.
     */
    private boolean editable;
    /**
     * User's Scheduler object.
     */
    private Scheduler scheduler;
    
    /**
     * Initial week number.
     */
    private int weekNum = 1;

    /**
     * Default Constructor.
     */
    public User() {
    }

    /**
     * Main Constructor.
     *
     * @param userName to be assigned to User record
     * @param lastName to be assigned to User record
     * @param firstName to be assigned to User record
     * @param password to be assigned to User record
     * @param admin privilege to be assigned to User record
     * @param employeeNumber to be assigned to User record
     */
    public User(final String userName,
        final String lastName, final String firstName,
        final String password,
        final boolean admin, final int employeeNumber) {
        this.userName = userName;
        this.lastName = lastName;
        this.firstName = firstName;
        this.password = password;
        this.admin = admin;
        this.employeeNumber = employeeNumber;
    }

    /**
     * Gets user name associated to this User account.
     *
     * @return userName
     */
    public String getUserName() {
        return userName;
    }
    /**
     * Sets this User account's user name.
     *
     * @param userName to apply to this User
     */
    public void setUserName(final String userName) {
        this.userName = userName;
    }

    /**
     * Gets last name associated to this User account.
     *
     * @return lastName
     */
    public String getLastName() {
        return lastName;
    }
    /**
     * Sets this User account's last name.
     *
     * @param lastName to apply to this User
     */
    public void setLastName(final String lastName) {
        this.lastName = lastName;
    }

    /**
     * Gets first name associated to this User account.
     *
     * @return firstName
     */
    public String getFirstName() {
        return firstName;
    }
    /**
     * Sets this User account's first name.
     *
     * @param firstName to apply to this User
     */
    public void setFirstName(final String firstName) {
        this.firstName = firstName;
    }

    /**
     * Gets password associated to this User account.
     *
     * @return password
     */
    public String getPassword() {
        return password;
    }
    /**
     * Sets this User account's password.
     *
     * @param password to apply to this User
     */
    public void setPassword(final String password) {
        this.password = password;
    }

    /**
     * Gets Admin permission associated this User account.
     *
     * @return admin
     */
    public boolean isAdmin() {
        return admin;
    }
    /**
     * Sets this User's Admin privileges.
     *
     * @param admin permission to apply to this User
     */
    public void setAdmin(final boolean admin) {
        this.admin = admin;
    }

    /**
     * Gets employee number associated this User account.
     *
     * @return employeeNumber
     */
    public int getEmployeeNumber() {
        return employeeNumber;
    }

    /**
     * Gets employee number in formatted string form.
     *
     * @return numString
     */
    public String getEmployeeNumberAsString() {
        String numString = Integer.toString(employeeNumber);
        int padding = EMPNUMDIGITS - numString.length();
        if (padding > 0) {
            numString = new String(new char[padding]).replace("\0", "0")
                                                            + numString;
        }
        return numString;
    }

    /**
     * Sets this User's employee number.
     *
     * @param employeeNumber to apply to this User
     */
    public void setEmployeeNumber(final int employeeNumber) {
        this.employeeNumber = employeeNumber;
    }

    /**
     * Gets current editing state of this User object.
     *
     * @return editable
     */
    public boolean isEditable() {
        return editable;
    }
    /**
     * Sets this User's editing state.
     *
     * @param editable state of User to change
     */
    public void setEditable(final boolean editable) {
        this.editable = editable;
    }

    /**
     * Gets this User's Scheduler object.
     *
     * @return Scheduler or null
     */
    public Scheduler getScheduler() {
        if (scheduler == null) {
            scheduler = new Scheduler();
            scheduler.setOwner(this);
        }
        return scheduler;
    }

    /**
     * Sets this User's assigned Scheduler object.
     *
     * @param scheduler to assign to this User
     */
    public void setScheduler(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

	public int getWeekNum() {
		return weekNum;
	}

	public void setWeekNum(int weekNum) {
		this.weekNum = weekNum;
	}
	
	public void incrWeekNum() {
		this.weekNum++;
	}

}
